2 * Adium is the legal property of its developers, whose names are listed in the copyright file included
3 * with this source distribution.
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11 * Public License for more details.
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #import "AIContentController.h"
20 #import "AIContentObject.h"
21 #import "AIListObject.h"
22 #import "AIHTMLDecoder.h"
24 @implementation AIContentObject
27 - (id)initWithChat:(AIChat *)inChat
28 source:(AIListObject *)inSource
29 destination:(AIListObject *)inDest
32 return([self initWithChat:inChat source:inSource destination:inDest date:inDate message:nil]);
34 - (id)initWithChat:(AIChat *)inChat
35 source:(AIListObject *)inSource
36 destination:(AIListObject *)inDest
38 message:(NSAttributedString *)inMessage
40 if((self = [super init]))
46 displayContentImmediately = YES;
48 postProcessContent = YES;
50 //Store source, dest, chat, ...
51 source = [inSource retain];
52 destination = [inDest retain];
53 message = [inMessage retain];
54 date = [(inDate ? inDate : [NSDate date]) retain];
56 chat = [inChat retain];
57 outgoing = ([source isKindOfClass:[AIAccount class]]);
66 [source release]; source = nil;
67 [destination release]; destination = nil;
68 [date release]; date = nil;
69 [message release]; message = nil;
70 [chat release]; chat = nil;
71 [userInfo release]; userInfo = nil;
87 - (void)setUserInfo:(id)inUserInfo
89 if(userInfo != inUserInfo){
91 userInfo = [inUserInfo retain];
95 //Comparing ------------------------------------------------------------------------------------------------------------
96 #pragma mark Comparing
97 //Content is similar if it's from the same source, of the same time, and sent within 5 minutes.
98 - (BOOL)isSimilarToContent:(AIContentObject *)inContent
100 if(source == [inContent source] && [[self type] compare:[inContent type]] == 0){
101 NSTimeInterval timeInterval = [date timeIntervalSinceDate:[inContent date]];
103 return(timeInterval > -300 && timeInterval < 300);
109 //Content is from the same day. If passed nil, content is from the current day.
110 - (BOOL)isFromSameDayAsContent:(AIContentObject *)inContent
112 NSCalendarDate *ourDate = [[self date] dateWithCalendarFormat:nil timeZone:nil];
113 NSCalendarDate *inDate = [(inContent ? [inContent date] : [NSDate date]) dateWithCalendarFormat:nil timeZone:nil];
115 return([ourDate dayOfCommonEra] == [inDate dayOfCommonEra]);
118 //Content --------------------------------------------------------------------------------------------------------------
120 //Message Source and destination
121 - (AIListObject *)source
125 - (AIListObject *)destination
130 //Date and time of this message
136 //Is this content incoming or outgoing?
141 - (void)_setIsOutgoing:(BOOL)inOutgoing
142 { //Hack for message view preferences
143 outgoing = inOutgoing;
146 //Chat containing this content
147 - (void)setChat:(AIChat *)inChat
157 - (void)setMessage:(NSAttributedString *)inMessage
159 if(message != inMessage){
161 message = [inMessage retain];
164 - (NSAttributedString *)message
169 //HTML string message
170 - (void)setMessageHTML:(NSString *)inMessageString
173 message = [[AIHTMLDecoder decodeHTML:inMessageString] retain];
175 - (NSString *)messageHTML
177 return [AIHTMLDecoder encodeHTML:message encodeFullString:YES];
180 //Plaintext string message
181 - (void)setMessageString:(NSString *)inMessageString
184 message = [[NSAttributedString alloc] initWithString:inMessageString
185 attributes:[[adium contentController] defaultFormattingAttributes]];
188 - (NSString *)messageString
190 return [message string];
194 //Behavior -------------------------------------------------------------------------------------------------------------
195 #pragma mark Behavior
197 * @brief Set if this content is passed through content filters
199 - (void)setFilterContent:(BOOL)inFilterContent
201 filterContent = inFilterContent;
204 * @brief Is this content passed through content filters?
206 - (BOOL)filterContent
208 return filterContent;
212 * @brief Set if this content is tracked
214 - (void)setTrackContent:(BOOL)inTrackContent
216 trackContent = inTrackContent;
219 * @brief Is this content tracked with notifications?
221 * If NO, the content will not trigger message sent/message received events such as a sound playing.
229 * @brief Set if this content is displayed
231 - (void)setDisplayContent:(BOOL)inDisplayContent
233 displayContent = inDisplayContent;
236 * @brief Is this content displayed?
238 * This will be NO for a content object such as an AIContentTyping object which is sent but not displayed
240 - (BOOL)displayContent
242 return displayContent;
246 * @brief Set if this content is displayed immediately
248 - (void)setDisplayContentImmediately:(BOOL)inDisplayContentImmediately
250 displayContentImmediately = inDisplayContentImmediately;
253 * @brief Should this content be displayed immediately?
255 * If NO, the object which created this content is responsible for posting Content_ChatDidFinishAddingUntrackedContent
256 * with an object of the associated AIChat to [adium notificationCenter] at some point in the future to request display.
258 - (BOOL)displayContentImmediately
260 return displayContentImmediately;
264 * @brief Set if the content should be sent
266 - (void)setSendContent:(BOOL)inSendContent{
267 sendContent = inSendContent;
270 * @brief Send the content?
277 * @brief Set if this content is post processed
279 - (void)setPostProcessContent:(BOOL)inPostProcessContent
281 postProcessContent = inPostProcessContent;
284 * @brief Post process this content?
286 * For example, this should be YES if the content is to be logged and NO if it is not.
288 - (BOOL)postProcessContent
290 return postProcessContent;